package dba.example.guice.module

import com.google.inject.AbstractModule
import dba.example.guice.init.Initialisation
import dba.example.guice.dao.CompanyDao
import com.google.inject.matcher.Matchers
import dba.example.guice.interceptors.LoggingMethodInterceptor
import dba.example.guice.dao.impl.CompanyDaoImpl
import com.google.inject.persist.jpa.JpaPersistModule
import dba.example.guice.finders.CompanyFinder
import com.google.inject.name.Names
import java.util.Properties
import dba.example.guice.dao.AccountDao
import dba.example.guice.dao.impl.AccountDaoImpl
import dba.example.guice.finders.AccountFinder

class ExampleModule (val jpa: Properties) extends AbstractModule {
  
  override def configure() {
    bind(classOf[Initialisation]).asEagerSingleton()
    bind(classOf[CompanyDao]).to(classOf[CompanyDaoImpl])
    bind(classOf[AccountDao]).to(classOf[AccountDaoImpl])

    //val lmi = new LoggingMethodInterceptor()
    //bindInterceptor(Matchers.inSubpackage("dba.example"), Matchers.any(), lmi)

    val jpaPersistModule = new JpaPersistModule("exampleDerby").properties(jpa)
    jpaPersistModule.addFinder(classOf[AccountFinder])
    jpaPersistModule.addFinder(classOf[CompanyFinder])

    install(jpaPersistModule)
  }

}